package com.mohan.yygh.cmn.controller;

import com.mohan.common.result.Result;
import com.mohan.model.cmn.Dict;
import com.mohan.yygh.cmn.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/admin/cmn/dict")
@CrossOrigin
@Api(tags = "字典")
public class DistController {
  @Autowired
  private DictService dictService;

  @GetMapping("/findChildData/{id}")
  @ApiOperation("根据数据id查询 子数据列表")
  public Result findChildData(@PathVariable Long id) {
    List<Dict> list = dictService.findChildData(id);
    return Result.ok(list);
  }

  @GetMapping("/exportData")
  public Result exportDict(HttpServletResponse response) {
    dictService.exportDict(response);
    return Result.ok();
  }

  @PostMapping("/importData")
  public Result importData(MultipartFile file) {
    dictService.importData(file);
    return Result.ok();
  }
}
